<template>
	<view >
		<cu-custom bgColor="bg-gradual-pink" :isBack="false">
			<!-- <block slot="backText">返回</block> -->

			<block slot="right">
			  <uni-icons type="home" size="20" color="white" class="home-icon" @click="goHome"></uni-icons>
			</block>
			<block slot="content">订单查询</block>
		</cu-custom>
<!-- 	  <view class="container">
		<view class="search-bar">
		  <view class="input-wrapper">
			  <input v-model="searchVal" placeholder="请输入查询数据"
			   @input="handleInput" 
			   :focus="focusStateProduct"
			   style="background-color: white;" 
			   autofocus
			   />
		  </view>
		  <button @click="search">查询</button>
		</view>
			<uni-table ref="table" :loading="loading" border stripe type="selection" emptyText="暂无更多数据" @selection-change="selectionChange">
				<uni-tr>
					<uni-th width="20" align="center">序号</uni-th>
					<uni-th width="150" align="center">内部单号</uni-th>
					<uni-th width="150" align="center">客户单号</uni-th>
					<uni-th align="center">客户名称</uni-th>
					<uni-th width="150" align="center">下单日期	</uni-th>
					<uni-th width="150" align="center">需求日期</uni-th>
					<uni-th width="150" align="center">金额</uni-th>
					<uni-th width="150" align="center">税额</uni-th>
					<uni-th width="150" align="center">状态</uni-th>
				</uni-tr>
				<uni-tr v-for="(item, index) in tableData" :key="index">
					<uni-td>{{ index + 1 }}</uni-td>
					<uni-td>{{ item.orderNumber }}</uni-td>
					<uni-td>
						<view class="name">{{ item.customerPoNumber }}</view>
					</uni-td>
					<uni-td align="center">{{ item.customerId_dictText }}</uni-td>
					<uni-td>{{ item.orderDate }}</uni-td>
					<uni-td>{{ item.deliveryDate }}</uni-td>
					<uni-td>{{ item.amount }}</uni-td>
					<uni-td>{{ item.taxAmount }}</uni-td>
					<uni-td>{{ item.status_dictText }}</uni-td>
				</uni-tr>
			</uni-table>
			<view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total" @change="change" /></view>
	  </view> -->
	  
	  <view class="example-body">
	  	<!-- <tabls refs="tabls"></tabls> -->
	  	<view class="container">
			<view class="search-bar">
			  <view class="input-wrapper">
				  <input v-model="searchVal" placeholder="请输入查询数据"
				   @input="handleInput" 
				   :focus="focusStateProduct"
				   style="background-color: white;" 
				   autofocus
				   />
			  </view>
			  <button @click="search">查询</button>
			  </view>
	  	  <!-- 标签栏 -->
	  	  <scroll-view class="tabs" scroll-x scroll-with-animation>
	  	    <view 
	  	      v-for="(tab, index) in tabs" 
	  	      :key="index" 
	  	      class="tab-item" 
	  	      :class="{ 'active': activeTab === index }"
	  	      @click="switchTab(index)"
	  	    >
	  	      {{ tab.title }}
	  	    </view>
	  	  </scroll-view>
	  	
	  	  <!-- 内容区域 -->
	  	  <view class="content">
			  <!-- :ref="'content' + index" v-for="(tab, index) in tabs[0]" :key="index" v-if="activeTab === 0" -->
	  	    <view  class="tab-content">
	  	      <uni-table ref="table0" :loading="tabs[0].loading" border stripe type="selection" v-if="activeTab === 0" emptyText="暂无更多数据" @selection-change="selectionChange">
	  	        <uni-tr>
	  	          <uni-th v-for="header in tabs[0].columns" :key="header.key" :width="header.width" :align="header.align">
	  	            {{ header.title }}
	  	          </uni-th>
	  	        </uni-tr>
	  	        <uni-tr v-for="(item, rowIndex) in tabs[0].data" :key="rowIndex">
	  	          <uni-td v-for="(header, colIndex) in tabs[0].columns" :key="colIndex">
	  	            <!-- 处理序号列 -->
	  	            <template v-if="header.key === 'index'">
	  	              {{ rowIndex + 1 }}
	  	            </template>
	  	            <!-- 处理其他列 -->
	  	            <template v-else >
	  	              {{ item[header.key] ? item[header.key] : '' }}
	  	            </template>
	  	          </uni-td>
	  	        </uni-tr>
	  	      </uni-table>
	  	      <uni-table ref="table1" :loading="tabs[1].loading" border stripe type="selection" v-if="activeTab === 1" emptyText="暂无更多数据" @selection-change="selectionChange">
	  	        <uni-tr>
	  	          <uni-th v-for="header in tabs[1].columns" :key="header.key" :width="header.width" :align="header.align">
	  	            {{ header.title }}
	  	          </uni-th>
	  	        </uni-tr>
	  	        <uni-tr v-for="(item, rowIndex) in tabs[1].data" :key="rowIndex">
	  	          <uni-td v-for="(header, colIndex) in tabs[1].columns" :key="colIndex">
	  	            <!-- 处理序号列 -->
	  	            <template v-if="header.key === 'index'">
	  	              {{ rowIndex + 1 }}
	  	            </template>
	  	            <!-- 处理其他列 -->
	  	            <template v-else >
	  	              {{ item[header.key] ? item[header.key] : '' }}
	  	            </template>
	  	          </uni-td>
	  	        </uni-tr>
	  	      </uni-table>		
	  	      <uni-table ref="table2" :loading="tabs[2].loading" border stripe type="selection" v-if="activeTab === 2" emptyText="暂无更多数据" @selection-change="selectionChange">
	  	        <uni-tr>
	  	          <uni-th v-for="header in tabs[2].columns" :key="header.key" :width="header.width" :align="header.align">
	  	            {{ header.title }}
	  	          </uni-th>
	  	        </uni-tr>
	  	        <uni-tr v-for="(item, rowIndex) in tabs[2].data" :key="rowIndex">
	  	          <uni-td v-for="(header, colIndex) in tabs[2].columns" :key="colIndex">
	  	            <!-- 处理序号列 -->
	  	            <template v-if="header.key === 'index'">
	  	              {{ rowIndex + 1 }}
	  	            </template>
					<template v-else-if="header.key === 'attachment'">
						<view>
							<image
							  class="image"
							  :src="getImage(item)"
							  @click="previewImage($event,item,rowIndex)"							  
							></image>
						  </view>
					</template>
					<template v-else-if="header.key=='abnormalDescription'">
						<view @click="openPop(item.abnormalDescription)" class="name"> {{ item.abnormalDescription ? (item.abnormalDescription.slice(0, 5) + (item.abnormalDescription.length > 5 ? '...' : '')) : "" }}</view>
					</template>
	  	            <!-- 处理其他列 -->
	  	            <template v-else >
	  	              {{ item[header.key] ? item[header.key] : '' }}
	  	            </template>
	  	          </uni-td>
	  	        </uni-tr>
	  	      </uni-table>	
	  	      <uni-table ref="table3" :loading="tabs[3].loading" border stripe type="selection" v-if="activeTab === 3" emptyText="暂无更多数据" @selection-change="selectionChange">
	  	        <uni-tr>
	  	          <uni-th v-for="header in tabs[3].columns" :key="header.key" :width="header.width" :align="header.align">
	  	            {{ header.title }}
	  	          </uni-th>
	  	        </uni-tr>
	  	        <uni-tr v-for="(item, rowIndex) in tabs[3].data" :key="rowIndex">
	  	          <uni-td v-for="(header, colIndex) in tabs[3].columns" :key="colIndex">
	  	            <!-- 处理序号列 -->
	  	            <template v-if="header.key === 'index'">
	  	              {{ rowIndex + 1 }}
	  	            </template>
	  	            <!-- 处理其他列 -->
	  	            <template v-else >
	  	              {{ item[header.key] ? item[header.key] : '' }}
	  	            </template>
	  	          </uni-td>
	  	        </uni-tr>
	  	      </uni-table>		
	  	      <uni-table ref="table4" :loading="tabs[4].loading" border stripe type="selection" v-if="activeTab === 4" emptyText="暂无更多数据" @selection-change="selectionChange">
	  	        <uni-tr>
	  	          <uni-th v-for="header in tabs[4].columns" :key="header.key" :width="header.width" :align="header.align">
	  	            {{ header.title }}
	  	          </uni-th>
	  	        </uni-tr>
	  	        <uni-tr v-for="(item, rowIndex) in tabs[4].data" :key="rowIndex">
	  	          <uni-td v-for="(header, colIndex) in tabs[4].columns" :key="colIndex">
	  	            <!-- 处理序号列 -->
	  	            <template v-if="header.key === 'index'">
	  	              {{ rowIndex + 1 }}
	  	            </template>
					<template v-else-if = "header.key == 'isClosed'" >
					  {{ item[header.key] && item[header.key] == 2   ? '已开票' : '未开票' }}
					</template>
	  	            <!-- 处理其他列 -->
	  	            <template v-else >
	  	              {{ item[header.key] ? item[header.key] : '' }}
	  	            </template>
	  	          </uni-td>
	  	        </uni-tr>
	  	      </uni-table>														
			  <view class="uni-pagination-box"><uni-pagination show-icon :page-size="pageSize" :current="pageCurrent" :total="total" @change="change" /></view>
			  
	  	    </view>
	  	  </view>
	  	</view>
	  </view>		
	  <view class="example-body">
		<drawer :show="subOrderDrawerShow" @cancel="subOrderCancel" @ensure="subOrderEnsure" >
			<view  style="margin-top: 240rpx;">
				<uni-table ref="itemTable" :loading="loading" border stripe type="selection" emptyText="暂无更多数据" @selection-change="selectionDrawChange">
					<uni-tr>
						<uni-th width="50" align="center">序号</uni-th>		
<!-- 						<uni-th width="150" align="center">工单号</uni-th>
						<uni-th width="150" align="center">客户</uni-th> -->
						<uni-th width="120" align="center">产品编码</uni-th>
						<uni-th width="150" align="center">客户料号</uni-th>
						<uni-th width="120" align="center">图号</uni-th>
						<uni-th width="120" align="center">产品名称</uni-th>
						<uni-th width="150" align="center">版本</uni-th>
						<uni-th width="120" align="center">数量</uni-th>
						<uni-th width="120" align="center">下单日期</uni-th>	
						<uni-th width="120" align="center">需求日期</uni-th>		
					    <uni-th	width="120" align="center">操作</uni-th>
					</uni-tr>
					<uni-tr v-for="(item1, index) in itemChilds" :key="index">
						<uni-td>{{ (index + 1) }}</uni-td>
<!-- 						<uni-td>{{ item1.workOrderNumber }}</uni-td>
						<uni-td>{{ item1.customerShortName }}</uni-td> -->
						<uni-td>{{ item1.productCode }}			</uni-td>
						<uni-td>		{{item1.custPoMaterial}}		</uni-td>
						  <uni-td>		{{item1.drawingNo}}		</uni-td>
						<uni-td>		{{item1.productName}}		</uni-td>
						<uni-td>		{{item1.productVer}}		</uni-td>
						<uni-td>		{{item1.qty}}		</uni-td>
						<uni-td>		{{item1.orderDate ? item1.orderDate : '' }}		</uni-td>
						<uni-td>		{{item1.deliveryDate ? item1.deliveryDate : '' }}		</uni-td>
						<uni-td>
							<view class="uni-group">
								<!-- <button class="uni-button" size="mini" type="primary">修改</button> -->
								<button class="uni-button" size="mini" @tap="addAbn(item1)" type="warn">客诉</button>
							</view>
<!-- 							<view class="uni-group">
								<button class="uni-button" size="mini" @tap="queryAbn(item1)" type="warn">客诉查询</button>
							</view> -->
						</uni-td>
					</uni-tr>
				</uni-table>
			  </view>
			</drawer>	
		</view>
		<view class="uni-padding-wrap">
			<uni-popup ref="popup" type="center">
			  <view class="contentPop">
					{{popupMessages}}		 
			  </view>
			</uni-popup>
		</view>
  </view>
</template>

<script>
import { ACCESS_TOKEN,USER_NAME,USER_INFO,SASS_TENANT_ID,EMPLOYEE_INFO,SASS_DOMAIN_ID,SASS_DOMAIN_NAME} from "@/common/util/constants"
import configService from '@/common/service/config.service.js';
import { forEach } from "../../common/luch-request/utils";
	import api from '@/api/api.js'
import CustomDownSearch from '@/components/my-componets/custom-down-search.vue'
import tableData from '../workorder/table/tableData.js'
	
export default {
	components: {
		CustomDownSearch,
	},
  data() {
    return {
	  subOrderDrawerShow:false,
      searchKeyword: '',
	  selectedOrderNumber:'',
	  selectedOrderItemId:'',
	  searchVal: '',
	  uuid : "47b4a254-bc96-424f-b11f-5bda3f2e75c5", //'ebfd5729-7f9e-4109-a025-077c17a9edcc',
	  tenantId : '22', //'22',
	  customerId : '1593806325081550849', //1593806325081550849
	  searchCustId: null,
		tableData: [],
		itemChilds : [],
		custList : [],
		custListText : [],
		// 每页数据量
		pageSize: 10,
		// 当前页
		pageCurrent: 1,
		// 数据总量
		total: 0,
		loading: false,
				activeTab: 0, // 当前激活的标签索引
				tabs: [
				  {
				    title: '未完订单',
				    loading: false,
				    columns: [
				      { title: '序号', key: 'index', width: '20', align: 'center' },
				      { title: '内部单号', key: 'orderNumber', width: '150', align: 'center' },
					  { title: '客户单号', key: 'realName', width: '100', align: 'center' },
					  { title: '下单日期', key: 'materialCode', width: '100', align: 'center' },
					  { title: '需求日期', key: 'materialModel', width: '100', align: 'center' },					  
					  { title: '金额', key: 'amount', width: '100', align: 'center' },
					  { title: '税额', key: 'taxAmount', width: '100', align: 'center' },
					  { title: '状态', key: 'status_dictText', width: '100', align: 'center' },
					  // { title: '毛需求数量', key: 'qty', width: '100', align: 'center' },
					  // { title: '物料类型', key: 'materialType', width: '100', align: 'center' },
					  // { title: '单位', key: 'unitId_dictText', width: '100', align: 'center' },
				   //    { title: '工单号', key: 'workOrderNumber',width: '150', align: 'center' },
					  // { title: '工单数量', key: 'itemQty', width: '100', align: 'center' },
					  // { title: 'BOM数量', key: 'bomQty', width: '100', align: 'center' },					  
				    ],
				    data: [
				    ]
				  },
				  {
				    title: '全部订单',
				    loading: false,
				    columns: [
				      { title: '序号', key: 'index', width: '20', align: 'center' },
				      { title: '内部单号', key: 'orderNumber', width: '150', align: 'center' },
					  { title: '客户单号', key: 'realName', width: '100', align: 'center' },
					  { title: '下单日期', key: 'materialCode', width: '100', align: 'center' },
					  { title: '需求日期', key: 'materialModel', width: '100', align: 'center' },					  
					  { title: '金额', key: 'amount', width: '100', align: 'center' },
					  { title: '税额', key: 'taxAmount', width: '100', align: 'center' },
					  { title: '状态', key: 'status_dictText', width: '100', align: 'center' },
					  // { title: '毛需求数量', key: 'qty', width: '100', align: 'center' },
					  // { title: '物料类型', key: 'materialType', width: '100', align: 'center' },
					  // { title: '单位', key: 'unitId_dictText', width: '100', align: 'center' },
				   //    { title: '工单号', key: 'workOrderNumber',width: '150', align: 'center' },
					  // { title: '工单数量', key: 'itemQty', width: '100', align: 'center' },
					  // { title: 'BOM数量', key: 'bomQty', width: '100', align: 'center' },					  
				    ],
				    data: [
				    ]
				  },				  
				  {
				    title: '客诉查询',
				    loading: false,
				    columns: [
				      { title: '序号', key: 'index', width: '20', align: 'center' },
				      { title: '内部单号', key: 'salseOrderNumber', width: '150', align: 'center' },
					  { title: '产品编码', key: 'productCode', width: '100', align: 'center' },
					  { title: '客户料号', key: 'custCode', width: '100', align: 'center' },
					  { title: '产品名称', key: 'productName', width: '100', align: 'center' },					  
					  { title: '异常单号', key: 'abnormalNumber', width: '100', align: 'center' },
					  { title: '异常描述', key: 'abnormalDescription', width: '100', align: 'center' },
					  { title: '不良图片', key: 'attachment', width: '100', align: 'center' },
					  { title: '不良数量', key: 'samplingQuantity', width: '100', align: 'center' },
					  { title: '单位', key: 'unitId_dictText', width: '100', align: 'center' },
					  { title: '时间', key: 'samplingDate', width: '100', align: 'center' },
					  
				    ],
				    data: [],					
				  },
				  {
				    title: '款项查询',
				    loading: false,
				    columns: [
				      { title: '序号', key: 'index', width: '20', align: 'center' },
				      { title: '上月期末余额', key: 'custPreMonthTotalAmount', width: '150', align: 'center' },
					  { title: '本月收到金额', key: 'custCurrMonthRecTotalAmount', width: '100', align: 'center' },
					  { title: '本月供货金额', key: 'custCurrMonthDNTotalAmount', width: '100', align: 'center' },
					  { title: '期末总欠金额', key: 'custAllMonthDNTotalAmount', width: '100', align: 'center' },
				    ],
				    data: []
				  },		
					{
					  title: '发票查询',
					  loading: false,
					  columns: [
						{ title: '序号', key: 'index', width: '20', align: 'center' },
						{ title: '对账单号', key: 'billNo', width: '150', align: 'center' },
						{ title: '开票状态', key: 'isClosed', width: '100', align: 'center' },
						  { title: '对账开始日', key: 'fromTime', width: '100', align: 'center' },
						  { title: '对账结束日期', key: 'toTime', width: '100', align: 'center' },
						  { title: '金额', key: 'amount', width: '100', align: 'center' },
						  { title: '税额', key: 'taxAmount', width: '100', align: 'center' },
					  ],
					  data: []
					},					
				],		
		
	  url : {
		   listAbn: '/abn/abnCustomerComplaints/list',
		   listAmount: '/acc/accReceipt/getCustomerAmount',
		   listInvoice: '/acc/accReceivable/list',
		   custList : '/bas/basCustomer/list',
		   list: '/som/somSalseOrder/list',
		   queryById : '/som/somSalseOrder/querySomSalseOrderItemByMainId',
		   queryAbnId : '/abn/abnCustomerComplaints/queryAbnCustomerComplaints',
		   login: '/sys/shareLinkLogin',
		   checkSign: '/sys/checkUuid',
	  },
	  firstDayOfMonth:"",
	  currentMonth:"",
	  popupMessages:"",
    };
  },
  onLoad(options) {
  	setTimeout(() => {
  	  console.log(options);
  	  if (options.uuid) {
  		this.uuid =options.uuid;
  	  } 
  	  if (options.customerId) {
  		this.customerId = options.customerId;
  	  } 
  	  if (options.tenantId) {
  		this.tenantId = options.tenantId;
  	  }	
	  if (this.uuid) {
		  this.checkSign()
	  }
  	}, 800);	  
	  
  		this.selectedIndexs = []
		this.selectedOrderItemIndexs = []
  		// this.getData(1)
  },
  created(){
	  this.getCusts()
  },
  methods: {
	  getImage(record) {
	  	if (record.attachment) {
	  		return api.getFileAccessHttpUrl(record.attachment.split(',')[0])
	  	}
	  },
	  previewImage(e,record,index) {
	  	// 获取图片列表，这里只有一张图片，可以直接放大
	  	if (!record.attachment) return
	  	let images = record.attachment.split(',');
	  	let _images = []
	  	images.forEach((v)=>{
	  		_images.push( api.getFileAccessHttpUrl(v)	)
	  	})
	  	// 调用uni.previewImage方法进行预览
	  	uni.previewImage({
	  	  current: _images[0], // 当前显示图片的http链接
	  	  urls: _images // 需要预览的图片http链接列表
	  	});
	    },	
		openPop(text) {
			if (text) {
				this.popupMessages = text
			} else {
				this.popupMessages = ''
			}				
			this.$refs['popup'].open()
			// this.$refs.popup.open('center')
			
		},
	  addAbn(item) {
		  
		  if (item) {
			  let params = JSON.parse(JSON.stringify(item))
		  	  params.salseOrderNumber = this.selectedOrderNumber
			  params.customerId= this.customerId
			  params.salseOrderItemId= item.id
			  params.id = null		  	
			console.log(item)
			console.log(params)
		    uni.navigateTo({
		  	url: '/pages/report/custInputProduceAbn?data=' + encodeURIComponent(JSON.stringify(params)) // 跳转到任务页面
		    })
		  }
		  
	  },
	  queryAbn(item) {
		  console.log(item)
	  },
	  switchTab(index) {
	    this.activeTab = index;
		if (index == 0) {
			this.getData(1)
		}
		if (index == 1) {
			this.getAllData(1)
		}
		if (index == 2) {
			this.getAbnData(1)
		}
		if (index == 3) {
			this.getAmountData(1)
		}	  
		if (index == 4) {
			this.getInvoiceData(1)
		}	
	  },
	  checkSign() {
		  let that = this
		this.loading = true;
		let params = {uuid:this.uuid + this.tenantId}
		this.$http.get(this.url.checkSign, {
				params: params
		}).then((res) => {
			that.checkString = JSON.stringify(res)
			if (res.data.success) {
				const result = res.data.result
				uni.setStorageSync(SASS_TENANT_ID,result.tenantId);
				this.biz = 'temp/' + result.tenantId  
				this.login()
			} else {
				this.$tip.toast(res.data.message)
			}
		}).catch(err => {
					that.err = JSON.stringify(err)
					that.$tip.error(err.data.message)
				}).finally(() => {
			that.loading = false
		})
	  },
	  login(){
		  let that = this
			this.loading = true;
			this.$http.post(this.url.login, {
					uuid: this.uuid,
					customerId: this.customerId,
					tenantId: this.tenantId,
			}).then((res) => {
				console.log(res)
				that.loginRes = JSON.stringify(res)
						if (res.data.success) {					
							const result = res.data.result
							const userInfo = result.userInfo
							uni.setStorageSync(ACCESS_TOKEN,result.token);
							uni.setStorageSync(USER_INFO,userInfo);
							this.getData(1)
							// this.loadData()
						} else {
							this.$tip.toast(res.data.message)
						}
				}).catch(err => {
					that.err = JSON.stringify(err)
					that.$tip.error(err.data.message)
				}).finally(() => {
					that.loading = false
				})
	  },	
		goHome() {
		  uni.navigateTo({
		    url: '/pages/login/login'
		  });
		},
	 handleTouchStart(event) {
		  // 获取触摸点的信息
		  const touch = event.touches[0];
		  const x = touch.clientX;
		  const y = touch.clientY;
		  console.log(`触摸开始，坐标为：(${x}, ${y})`);
		  this.$refs.selSupp.handelDropDown(x,y)
		},	  
	  getCusts() {
	  	console.log("beging find cust.")
	  	this.$http.get(
	  		this.url.custList, {
	  			params: {
	  				pageSize: 1000,
	  				status:1
	  			}
	  		}).then(res => {
	  		console.log("res::cust>", res)
	  		if (res.data.result.records) {
	  			let data = res.data.result.records
	  			this.custList = []
	  			data.forEach((item) => {
	  				let obj = {
	  					value: item.id,
	  					text: item.shortName
	  				}
	  				this.custList.push(obj)
					this.custListText.push(obj.text)
	  			})
	  		}
	  	})
	  },
	  handleDetail(id){
		  let that = this
		  let params = {
		  	'id' : id,
		  }
		  if (this.activeTab == 2) {
			  
		  } else if (this.activeTab == 0 || this.activeTab == 1) {
			 this.loading = true
			 this.$http.get(this.url.queryById, {
			 	params: params
			 }).then(res => {
			 
			 	this.loading = false
			 	that.itemChilds = res.data.result.records || res.data.result;
			 	// console.log(that.itemChilds)
			 	// console.log(res.data.result)
				that.$nextTick(()=>{
					this.subOrderDrawerShow = true
				})			 			
			 }) 
		  } else {
			  
		  }
	  },
		subOrderCancel() {
			console.log('您点击了取消按钮')
			this.subOrderDrawerShow = false;
		},
		//确定
		subOrderEnsure(){
			console.log('您点击了确定按钮')
			this.subOrderDrawerShow = false;
		},		  
	  setFocusProduct() {
		let that = this
		this.$nextTick(()=>{
			setTimeout(() => {
						that.focusStateProduct = true
				},1000)
		})
	  
	  },
	  handleInput() {
		  
	  },
	  selectedItems() {
	  	  			return this.selectedIndexs.map(i => this.tableData[i])
	  	  		},
		// 多选
		selectionDrawChange(e) {
			console.log(e.detail.index)
			this.selectedOrderItemIndexs = e.detail.index
			if (this.selectedOrderItemIndexs.length == 1) {
				let row = this.itemChilds[this.selectedOrderItemIndexs[0]]
				console.log(row)
				let params = {
				  productCode: row.productCode,
				  orderNumber: this.selectedOrderNumber
				}
			  uni.navigateTo({
				url: '/pages/report/queryWorkOrder?data=' + encodeURIComponent(JSON.stringify(params)) // 跳转到任务页面
			  })
			}
			
		},
		selectionChange(e) {
			console.log(e.detail.index)
			this.selectedIndexs = e.detail.index
			if (this.selectedIndexs.length == 1) {
				let rows = this.selectedItems()
				if (this.activeTab == 0 || this.activeTab == 1) {
					this.selectedOrderNumber = rows[0].orderNumber
					this.handleDetail(rows[0].id)
				}
			}
		},
		//批量删除
		delTable() {
			console.log(this.selectedItems())
		},
		// 分页触发
		change(e) {
			let index = this.activeTab
			 this.$nextTick(() => {
				if (index == 0) {
					this.$refs.table0.clearSelection()
					this.selectedIndexs.length = 0
					this.getData(e.current)
				}
				if (index == 1) {
					this.$refs.table1.clearSelection()
					this.selectedIndexs.length = 0
					this.getAllData(e.current)
				}
				if (index == 2) {
					this.$refs.table2.clearSelection()
					this.selectedIndexs.length = 0
					this.getAbnData(e.current)
				}
				if (index == 3) {
					this.$refs.table3.clearSelection()
					this.selectedIndexs.length = 0
					this.getAmountData(e.current)
				}	
				if (index == 4) {
					this.$refs.table4.clearSelection()
					this.selectedIndexs.length = 0
					this.getInvoiceData(e.current)
				}	
			})

		},
		clearSearchKeyword() {
		  this.searchVal = ''
		},
		// 搜索
		search() {
		
			// this.getData(1, this.searchVal)
			
			let index = this.activeTab
			 this.$nextTick(() => {
				if (index == 0) {
					this.$refs.table0.clearSelection()
					this.selectedIndexs.length = 0
					this.getData(1,this.searchVal)
				}
				if (index == 1) {
					this.$refs.table1.clearSelection()
					this.selectedIndexs.length = 0
					this.getAllData(1,this.searchVal)
				}
				if (index == 2) {
					this.$refs.table2.clearSelection()
					this.selectedIndexs.length = 0
					this.getAbnData(1,this.searchVal)
				}
				if (index == 3) {
					this.$refs.table3.clearSelection()
					this.selectedIndexs.length = 0
					this.getAmountData(1,this.searchVal)
				}	
				if (index == 4) {
					this.$refs.table4.clearSelection()
					this.selectedIndexs.length = 0
					this.getInvoiceData(1,this.searchVal)
				}	
			})
		},
        getData(pageCurrent, value = '') {
			    if (!this.customerId || this.customerId == "") {
					this.$tip.error("请选择客户")
					return
				}
				this.pageCurrent = pageCurrent
				let that = this
				let params = {
					'queryName' : value,
					'pageNo': this.pageCurrent,
					'pageSize': this.pageSize,
					'column': 'createTime,updateTime',					
					'order': 'desc',
				}
				let superArr = []
				superArr.push({"rule":"eq","type":"string","val":'3',"field":"so.status"})
				superArr.push({"rule":"eq","type":"string","val":this.customerId,"field":"so.customerId"})
				params.superQueryMatchType = 'and'
				params.superQueryParams = encodeURIComponent(JSON.stringify(superArr))
				
				this.loading = true
				this.$http.get(this.url.list, {
					params: params
				}).then(res => {
					this.loading = false
					this.tableData = res.data.result.records || res.data.result;
					console.log(this.tableData)
					this.tabs[0].data = this.tableData
					this.setFocusProduct()
					if (res.data.result.total) {
						this.total = res.data.result.total						
					} else {
						this.total = 0
					}
				})
			},		
		getAllData(pageCurrent, value = '') {
			if (!this.customerId || this.customerId == "") {
				this.$tip.error("请选择客户")
				return
			}
				this.pageCurrent = pageCurrent
				let that = this
				let params = {
					'queryName' : value,
					'pageNo': this.pageCurrent,
					'pageSize': this.pageSize,
					'column': 'createTime,updateTime',					
					'order': 'desc',
				}
				let superArr = []
				superArr.push({"rule":"in","type":"string","val":'3,4',"field":"so.status"})
				superArr.push({"rule":"eq","type":"string","val":this.customerId,"field":"so.customerId"})
				params.superQueryMatchType = 'and'
				params.superQueryParams = encodeURIComponent(JSON.stringify(superArr))
				
				this.loading = true
				this.$http.get(this.url.list, {
					params: params
				}).then(res => {
					this.loading = false
					this.tableData = res.data.result.records || res.data.result;
					this.tabs[1].data = this.tableData
					console.log(this.tableData)
					this.setFocusProduct()
					if (res.data.result.total) {
						this.total = res.data.result.total						
					} else {
						this.total = 0
					}
				})
			},		
		getAbnData(pageCurrent, value = '') {
			    if (!this.customerId || this.customerId == "") {
					this.$tip.error("请选择客户")
					return
				}
				this.pageCurrent = pageCurrent
				let that = this
				let params = {
					'queryName' : value,
					'pageNo': this.pageCurrent,
					'pageSize': this.pageSize,
					'column': 'createTime,updateTime',					
					'order': 'desc',
				}
				let superArr = []
				// superArr.push({"rule":"in","type":"string","val":'3,4',"field":"so.status"})
				superArr.push({"rule":"eq","type":"string","val":this.customerId,"field":"cc.customerId"})
				params.superQueryMatchType = 'and'
				params.superQueryParams = encodeURIComponent(JSON.stringify(superArr))
				
				this.loading = true
				this.$http.get(this.url.listAbn, {
					params: params
				}).then(res => {
					this.loading = false
					this.tableData = res.data.result.records || res.data.result;
					this.tabs[2].data = this.tableData
					console.log(this.tableData)
					this.setFocusProduct()
					if (res.data.result.total) {
						this.total = res.data.result.total						
					} else {
						this.total = 0
					}
				})
			},		
			
		getInvoiceData(pageCurrent, value = '') {
			    if (!this.customerId || this.customerId == "") {
					this.$tip.error("请选择客户")
					return
				}
				this.pageCurrent = pageCurrent
				let that = this
				let params = {
					'queryName' : value,
					'pageNo': this.pageCurrent,
					'pageSize': this.pageSize,
					'column': 'createTime,updateTime',					
					'order': 'desc',
				}
				let superArr = []
				// superArr.push({"rule":"in","type":"string","val":'3,4',"field":"so.status"})
				superArr.push({"rule":"eq","type":"string","val":this.customerId,"field":"ar.customerId"})
				params.superQueryMatchType = 'and'
				params.superQueryParams = encodeURIComponent(JSON.stringify(superArr))
				
				this.loading = true
				this.$http.get(this.url.listInvoice, {
					params: params
				}).then(res => {
					this.loading = false
					this.tableData = res.data.result.records || res.data.result;
					// if (this.tableData && this.tableData.length>0) {
					// 	this.tableData.forEach((item)=>{
					// 	  item.isClosed = item.isClosed && item.isClosed == 2? "已开票" : "未开票"
					// 	})
					// }
					this.tabs[4].data = this.tableData
					console.log(this.tableData)
					// this.setFocusProduct()
					if (res.data.result.total) {
						this.total = res.data.result.total						
					} else {
						this.total = 0
					}
				})
			},				
			getAmountData(pageCurrent, value = '') {
				if (!this.customerId || this.customerId == "") {
					this.$tip.error("请选择客户")
					return
				}
				this.pageCurrent = pageCurrent
				let that = this
				this.firstDayOfMonth = "";
				this.currentMonth = "";
				this.getFirstDayOfMonth();
				this.getMonthInFormat()
				let params = {
					'id' : this.customerId,
					'date': this.firstDayOfMonth,
					'month': this.currentMonth,
				}
				// let superArr = []
				// superArr.push({"rule":"eq","type":"string","val":this.customerId,"field":"so.customerId"})
				// params.superQueryMatchType = 'and'
				// params.superQueryParams = encodeURIComponent(JSON.stringify(superArr))
				
				this.loading = true
				this.$http.get(this.url.listAmount, {
					params: params
				}).then(res => {
					this.loading = false
					this.tableData = res.data.result.records || res.data.result;
					this.tabs[3].data = [this.tableData]
					console.log(this.tableData)
					// this.setFocusProduct()
					if (res.data.result.total) {
						this.total = res.data.result.total						
					} else {
						this.total = 0
					}
				})
			},		
		// 获取数据			
		// 获取数据
		getData1(pageCurrent, value = '') {
			this.loading = true
			this.pageCurrent = pageCurrent
			this.request({
				pageSize: this.pageSize,
				pageCurrent: pageCurrent,
				value: value,
				success: res => {
					// console.log('data', res);
					this.tableData = res.data
					this.total = res.total
					this.loading = false
				}
			})
		},
	  // 伪request请求
		request(options) {
			const { pageSize, pageCurrent, success, value } = options
			let total = tableData.length
			let data = tableData.filter((item, index) => {
				const idx = index - (pageCurrent - 1) * pageSize
				return idx < pageSize && idx >= 0
			})
			if (value) {
				data = []
				tableData.forEach(item => {
					if (item.name.indexOf(value) !== -1) {
						data.push(item)
					}
				})
				total = data.length
			}
  
			setTimeout(() => {
				typeof success === 'function' &&
					success({
						data: data,
						total: total
					})
			}, 500)
		},
		  getFirstDayOfMonth(inputDate) {
			  // 若未传入日期，则使用当前日期
			  const currentDate = inputDate || new Date(); 
			  // 创建一个新日期对象，将日期设置为 1 号
			  const firstDay = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1);
			  // 格式化日期，示例格式为 YYYY-MM-DD
			  const year = firstDay.getFullYear();
			  const month = String(firstDay.getMonth() + 1).padStart(2, '0');
			  const day = String(firstDay.getDate()).padStart(2, '0');
			  this.firstDayOfMonth = `${year}-${month}-${day}`;
		  },
		getMonthInFormat(inputDate) {
			// 若未传入日期，则使用当前日期
			const currentDate = inputDate || new Date(); 
			const year = currentDate.getFullYear();
			// 月份从 0 开始计数，所以要加 1，同时格式化为两位数
			const month = String(currentDate.getMonth() + 1).padStart(2, '0');
			this.currentMonth = `${year}-${month}`;
		}
  }
};
</script>

<style scoped>
.input-wrapper {
  position: relative;
  flex: 1;
}
  .home-icon {
    // position: absolute;
    // top: 20rpx;
    margin-left: 10px;
  }
.input-wrapper input {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  margin-right: 10px;
   box-sizing: border-box; /* 确保内边距和边框不会增加元素的宽度 */
}
.clear-button {
  position: absolute;
  top: 50%;
  right: 20px; /* 调整按钮的位置，避免被输入框的边框遮挡 */
  transform: translateY(-50%);
  background: none;
  border: none;
  color: #999;
  font-size: 16px;
  cursor: pointer;
  z-index: 1; /* 确保按钮在最上层，不会被其他元素遮挡 */
}	
.container {
  padding: 6px;
}
.search-bar {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}
.search-bar input {
  flex: 1;
  height: 40px;
  padding: 0 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  margin-right: 10px;
}
.search-bar button {
  height: 40px;
  padding: 0 20px;
  background-color: #007aff;
  color: #fff;
  border: none;
  border-radius: 5px;
  align-items: center;
  line-height: 40px;
}
  
  .tabs {
    white-space: nowrap;
    border-bottom: 1rpx solid #eee;
  }
  
  .tab-item {
    display: inline-block;
    padding: 20rpx 30rpx;
    font-size: 28rpx;
    color: #666;
  }
  
  .tab-item.active {
    color: #007AFF;
    border-bottom: 4rpx solid #007AFF;
  }
  
  .content {
    padding: 20rpx 0;
  }
  .image {
     width: 30px; /* 设置图片宽度 */
     height: 20px; /* 设置图片高度 */
   }	
   .contentPop {
     padding: 20px;
      border-radius: 5px;
     background-color: #fff;
   }
  .tab-content {
    font-size: 28rpx;
    color: #333;
  }
uni-table {
  margin-bottom: 20px;
}
uni-pagination {
  display: flex;
  justify-content: center;
}
</style>